package com.design.masterWorker;

import java.util.Map;
import java.util.Set;

public class PlusWorker extends Worker {
    @Override
    public Object handle(Object input) {
        Integer i = (Integer) input;
        return i+1;
    }

    public static void main(String[] args) {
        Master master = new Master(new PlusWorker(), 5);
        for (int i = 0; i < 100; i++) {
            master.submit(i); //�ύһ�ٸ�������
        }
        master.execute(); //��ʼ����
        int re = 0;
        Map<String, Object> resultMap = master.getResultMap();
        while (resultMap.size() > 0 || !master.isComplete()) {
            Set<String> keys = resultMap.keySet();
            String key = null;
            for (String k : keys) {
                key = k;
                break;
            }
            Integer i = null;
            if (key != null) {
                i = (Integer) resultMap.get(key);   //�ӽ�����л�ȡ���
            }
            if (i != null) {
                re += i;        //���ս��
            }
            if (key != null) {
                resultMap.remove(key);      //�Ƴ��Ѿ������������
            }
        }
        System.out.println("result: " + re);
    }
}
